﻿using System;
using System.IO;

namespace Visitor
{
    public class ListVisitor : Visitor
    {
        private string currentDir;

        public ListVisitor()
        {
            this.currentDir = "";
        }


        public override void Visit(File file)
        {
            Console.WriteLine(Path.Combine(currentDir, file.ToString()));
        }

        public override void Visit(Directory directory)
        {
            Console.WriteLine(Path.Combine(currentDir, directory.ToString()));

            string saveDir = currentDir;
            currentDir = Path.Combine(currentDir, directory.GetName());

            foreach (Entry entry in directory)
            {
                entry.Accept(this);
            }

            currentDir = saveDir;
        }
    }
}
